package com.aigao.golf.Utils;

import com.aigao.golf.common.base.BaseModel;
import com.aigao.golf.common.base.MyBaseService;
import tk.mybatis.mapper.entity.Example;

import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;

/**
 * @author QiangHe
 * @date 2018/1/10 12:48
 */
public class DaoUtil {
    public static int deleteById( MyBaseService service,String id,Class<?> entityClass){
        Example example = new Example(entityClass);
        Example.Criteria criteria = example.createCriteria();
        criteria.andEqualTo("id",id);
        try {
            Object object = entityClass.newInstance();
            Method method = entityClass.getDeclaredMethod("setFlag",Integer.class);
            method.invoke(object,1);
            return service.updateByExampleSelective((BaseModel<String>) object,example);
        } catch (InstantiationException e) {
            e.printStackTrace();
        } catch (IllegalAccessException e) {
            e.printStackTrace();
        } catch (NoSuchMethodException e) {
            e.printStackTrace();
        } catch (InvocationTargetException e) {
            e.printStackTrace();
        }
        return 0;
    }
}
